package com.tedu.openmedical.statistics.service.impl;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class DateFormatter {
    public static void main(String[] args) {
        String dateString = "Thu Jul 04 00:00:00 CST 2024";

        try {
            // 创建DateTimeFormatter
            DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);

            // 解析日期字符串
            LocalDateTime dateTime = LocalDateTime.parse(dateString, inputFormatter);

            // 提取日期部分
            LocalDate dateOnly = dateTime.toLocalDate();

            // 创建新的DateTimeFormatter
            DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            // 格式化日期
            String formattedDate = dateOnly.format(outputFormatter);

            System.out.println("转换后的日期: " + formattedDate);
        } catch (Exception e) {
            System.err.println("日期解析错误: " + e.getMessage());
        }
    }
}
